package com.example.bestudentsystem.demos.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bestudentsystem.demos.web.pojo.Inform;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface InformMapper extends BaseMapper<Inform> {
    @Results({
            @Result(property = "title", column = "title"),
            @Result(property = "content", column = "content"),
            @Result(property = "cno", column = "cno"),
            @Result(property = "time_start", column = "time_start"),
            @Result(property = "time_end", column = "time_end")
    })
    @Select("SELECT inform.title, inform.content, inform.cno, inform.time_start, inform.time_end " +
            "FROM inform " +
            "JOIN sc ON inform.cno = sc.cno " +
            "WHERE sc.sno = #{sno}")
    List<Inform> getInform1BySno(String sno);

    @Results({
            @Result(property = "title", column = "title"),
            @Result(property = "content", column = "content"),
            @Result(property = "cno", column = "cno"),
            @Result(property = "time_start", column = "time_start"),
            @Result(property = "time_end", column = "time_end")
    })
    @Select("SELECT DISTINCT inform.* " +
            "FROM inform " +
            "JOIN sc ON inform.cno = sc.cno " +
            "WHERE sc.sno LIKE CONCAT('%',#{sno},'%') AND inform.title LIKE CONCAT('%',#{title},'%') " +
            "ORDER BY inform.time_start DESC")
    IPage<Inform> getInform(IPage<Inform> iPage,String sno,String title);
    @Select("SELECT COUNT(time_end) FROM inform WHERE title='签到' AND cno=#{cno}")
    Integer getSignInCount(String cno);
}
